home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 2.toast / pc / sample code / sound / audioconverter / audioconvert.h < prev    next >
Encoding:
Text File  |  2000-06-23  |  6.6 KB  |  257 lines

  1. //////////
  2. //
  3. //    File:        AudioConvert.h
  4. //
  5. //    Contains:    Header file for code showing how to use the Sound Manager's SoundConverter routines. 
  6. //
  7. //    Written by:    Jim Reekes
  8. //    Revised by: Tim Monroe
  9. //
  10. //    Copyright:    © 1999 by Apple Computer, Inc., all rights reserved.
  11. //
  12. //    Change History (most recent first):
  13. //
  14. //       <1>         03/09/99    rtm        first file from jr; added some comments, and added Windows-specific code
  15. //       
  16. //////////
  17.  
  18. //////////
  19. //
  20. // header files
  21. //       
  22. //////////
  23.  
  24. #ifndef __AIFF__
  25. #include <AIFF.h>
  26. #endif
  27.  
  28. #ifndef __COMPONENTS__
  29. #include <Components.h>
  30. #endif
  31.  
  32. #ifndef __ERRORS__
  33. #include <Errors.h>
  34. #endif
  35.  
  36. #ifndef __FILETYPESANDCREATORS__
  37. #include <FileTypesAndCreators.h>
  38. #endif
  39.  
  40. #ifndef __FIXMATH__
  41. #include <FixMath.h>
  42. #endif
  43.  
  44. #ifndef __FONTS__
  45. #include <Fonts.h>
  46. #endif
  47.  
  48. #ifndef __FP__
  49. #include <fp.h>
  50. #endif
  51.  
  52. #ifndef __MACMEMORY__
  53. #include <MacMemory.h>
  54. #endif
  55.  
  56. #ifndef __MACTYPES__
  57. #include <MacTypes.h>
  58. #endif
  59.  
  60. #ifndef __MENUS__
  61. #include <Menus.h>
  62. #endif
  63.  
  64. #ifndef __MOVIES__
  65. #include <Movies.h>
  66. #endif
  67.  
  68. #ifndef __MOVIESFORMAT__
  69. #include <MoviesFormat.h>
  70. #endif
  71.  
  72. #ifndef __QUICKDRAW__
  73. #include <Quickdraw.h>
  74. #endif
  75.  
  76. #ifndef __QUICKTIMECOMPONENTS__
  77. #include <QuickTimeComponents.h>
  78. #endif
  79.  
  80. #ifndef __RESOURCES__
  81. #include <Resources.h>
  82. #endif
  83.  
  84. #ifndef __SOUND__
  85. #include <Sound.h>
  86. #endif
  87.  
  88. #ifndef __STRINGS__
  89. #include <Strings.h>
  90. #endif
  91.  
  92. #ifndef _STDDEF_H
  93. #include <stddef.h>
  94. #endif
  95.  
  96. // Windows-specific header files
  97. #if TARGET_OS_WIN32
  98.  
  99.     #ifndef __QTML__
  100.     #include <QTML.h>
  101.     #endif
  102.     
  103.     #include <windows.h>
  104.     
  105. #endif
  106.  
  107.  
  108. //////////
  109. //
  110. // compiler flags and defines
  111. //       
  112. //////////
  113.  
  114. // turns on debugging code
  115. #define _DEBUG
  116.  
  117. #if TARGET_OS_WIN32
  118. #define PASCAL_RTN
  119. #endif
  120.  
  121. #if TARGET_OS_MAC
  122. #define PASCAL_RTN                pascal
  123. #endif
  124.  
  125.  
  126. //////////
  127. //
  128. // constants
  129. //       
  130. //////////
  131.  
  132. enum {
  133.     kFileBufferSize                = (200*1024),
  134.     kMaxSndConvtBufferSize        = (20*1024),        // upper limit for sound converter's in or out buffer
  135.     rCustomGetFileDialog        = 1000,                // resource ID for custom Std File Dialog
  136.     kFileNameEditTextBox        = 10,                // item in custom Std File Dialog
  137.     kOutputAIFFButton            = 13,                // item in custom Std File Dialog
  138.     kOutputMovieButton            = 14                // item in custom Std File Dialog
  139. };
  140.  
  141. #define kMovieFileSaveName        "Sound.mov"            // default name for saving a movie file
  142. #define kAIFFFileSaveName        "Sound.aiff"        // default name for saving an AIFF file
  143.  
  144.  
  145. //////////
  146. //
  147. // function prototypes
  148. //       
  149. //////////
  150.  
  151. OSErr                             AudConv_ConvertToAIFF (ConstFSSpecPtr theInputFSSpec, ConstFSSpecPtr theOutputFSSpec, SoundComponentDataPtr theDestInfo);
  152. OSErr                             AudConv_ConvertToMovie (ConstFSSpecPtr theInputFSSpec, ConstFSSpecPtr theOutputFSSpec, SoundComponentDataPtr theDestInfo);
  153. OSErr                            AudConv_GetDataFromAIFF (short theRefNum, SoundComponentDataPtr theSourceInfo, long *theSourceOffset, long *theSourceSize, Handle *theDestCompParams);
  154. OSErr                            AudConv_ConvertAudioIntoHandle (    SoundComponentDataPtr theSourceInfo, 
  155.                                                                     Handle theSourceCompParamsHandle,
  156.                                                                     Handle theDestHandle, 
  157.                                                                     SoundComponentDataPtr theDestInfo,
  158.                                                                     Handle *theDestCompParamsHandle, 
  159.                                                                     CompressionInfoPtr theDestCompInfo);
  160. OSErr                            AudConv_WriteAudioToHandle (SoundConverter theConverter, SoundComponentDataPtr theSourceInfo, short theSourceBytesPerFrame, SoundComponentDataPtr theDestInfo, Handle theDestHandle);
  161. OSErr                            AudConv_GetOutputFormat (SoundComponentDataPtr theDestInfo);
  162. OSErr                            AudConv_SetFPosToChunk (short theRefNum, ID theChunkID);
  163. OSErr                            AudConv_PrepFileAsAIFF (short theOutputFile, SoundComponentDataPtr theDestInfo, Handle theDestParams);
  164. OSErr                            AudConv_FinishFileAsAIFF (short outputFile, unsigned long destFramesMoved, unsigned long destBytesMoved);
  165. OSErr                            AudConv_PutAudioIntoTrack (Track theTrack, Handle theDestAudioData, SoundComponentDataPtr destInfo, Handle destCompParams, CompressionInfoPtr destCompInfo);
  166. PASCAL_RTN short                AudConv_SFGetDialogHook (short theItem, DialogPtr theDialog, void *theOutputAIFF);
  167.  
  168.  
  169. //////////
  170. //
  171. // failure handling macros
  172. //       
  173. //////////
  174.  
  175. /*
  176.     Some macros used to check for errors and also to allow for
  177.     handling them by using a goto statement.  This makes the source
  178.     code easier to read.  It will break into the debugger with a
  179.     message showing the condition that caused the failure.  In some
  180.     of the macros the debug message is removed but goto remains.  In
  181.     other macros all of it is removed when doing a non-debug build.
  182.  
  183.     Note that these macros use the "\p" construct for creating
  184.     Pascal strings at compile time.  Most non-Mac compilers do
  185.     not recognize this, give a warning, and put 'p' as the first
  186.     character of the string.  You can ignore the warning because
  187.     the non-Mac version of DebugStr deals with this just fine.
  188.     For Microsoft's Visual C++, we suppress the warning below.
  189. */
  190. #if defined(_MSC_VER) && !defined(__MWERKS__)
  191.     // Visual C++ from Microsoft
  192.     #pragma warning(disable:4129) // unrecognized character escape sequence
  193. #endif
  194.  
  195. // This checks for the exception, and if true then goto handler
  196. #ifdef _DEBUG
  197. #define FailIf(cond, handler)                                \
  198.     if (cond) {                                                \
  199.         DebugStr((ConstStr255Param)"\p"#cond " goto " #handler);    \
  200.         goto handler;                                        \
  201.     } else 0
  202. #else
  203. #define FailIf(cond, handler)                                \
  204.     if (cond) {                                                \
  205.         goto handler;                                        \
  206.     } else 0
  207. #endif
  208.  
  209. // This checks for the exception, and if true do the action and goto handler
  210. #ifdef _DEBUG
  211. #define FailWithAction(cond, action, handler)                \
  212.     if (cond) {                                                \
  213.         DebugStr((ConstStr255Param)"\p"#cond " goto " #handler);    \
  214.         { action; }                                            \
  215.         goto handler;                                        \
  216.     } else 0
  217. #else
  218. #define FailWithAction(cond, action, handler)                \
  219.     if (cond) {                                                \
  220.         { action; }                                            \
  221.         goto handler;                                        \
  222.     } else 0
  223. #endif
  224.  
  225. // This will insert debugging code in the application to check conditions
  226. // and displays the condition in the debugger if true.  This code is
  227. // completely removed in non-debug builds.
  228. #ifdef _DEBUG
  229. #define FailMessage(cond)                                    \
  230.     if (cond)                                                \
  231.         DebugStr((ConstStr255Param)"\p"#cond);                \
  232.     else 0
  233. #else
  234. #define FailMessage(cond)
  235. #endif
  236.  
  237. // This allows you to test for the result of a condition (i.e. CloseComponent)
  238. // and break if it returns a non zero result, otherwise it ignores the result.
  239. // When a non-debug build is done, the result is ignored.
  240. #ifdef _DEBUG
  241. #define ErrorMessage(cond)                                    \
  242.     if (cond)                                                \
  243.         DebugStr((ConstStr255Param)"\p"#cond);                \
  244.     else 0
  245. #else
  246. #define ErrorMessage(cond)        cond
  247. #endif
  248.  
  249. // This will display a given message in the debugger, this code is completely
  250. // removed in non-debug builds.
  251. #ifdef _DEBUG
  252. #define DebugMessage(s)            DebugString((ConstStr255Param)s)
  253. #else
  254. #define DebugMessage(s)
  255. #endif
  256.  
  257.